package com.amumu.drama.admin.modules.member.controller;

import com.amumu.drama.admin.modules.member.dto.req.UmsMemberListQuery;
import com.amumu.drama.admin.modules.member.dto.req.UmsMemberStatusReq;
import com.amumu.drama.admin.modules.member.dto.resp.UmsMemberDetail;
import com.amumu.drama.admin.modules.member.dto.resp.UmsMemberListResp;
import com.amumu.drama.admin.modules.member.service.UmsAdminMemberService;
import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.base.api.CommonResult;
import com.amumu.drama.model.UmsMember;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户搜索")
@RequestMapping("/v1/admin/member")
@RestController
public class UmsMemberController {

    @Autowired
    private UmsAdminMemberService umsMemberService;

    @ApiOperation("查询用户列表（可以弃用）")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public CommonResult<CommonPage<UmsMember>> search(@RequestParam(required = false) String phoneNum,
                                                      @RequestParam(required = false, defaultValue = "0") Integer pageNum,
                                                      @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        List<UmsMember> memberList = umsMemberService.search(phoneNum, pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(memberList));
    }

    @ApiOperation("查询用户列表")
    @PostMapping("/queryList")
    public CommonResult<CommonPage<UmsMemberListResp>> queryListUmsMember(@RequestBody @Validated UmsMemberListQuery request) {
        return CommonResult.success(umsMemberService.queryListUmsMemberByPage(request));
    }

    @ApiOperation("查询用户详情")
    @GetMapping(value = "/getMemberDetail/{memberId}")
    public CommonResult<UmsMemberDetail> getMemberDetail(@PathVariable Long memberId) {
        return CommonResult.success(umsMemberService.getMemberDetail(memberId));
    }

    @ApiOperation("封禁解封账号/启用暂定邀请奖励")
    @PostMapping("/enableStatus")
    public CommonResult enableStatus(@RequestBody @Validated UmsMemberStatusReq request) {
        umsMemberService.enableStatus(request);
        return CommonResult.success();
    }

}
